package init;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by wangyg 
 * on 2017/3/23 9:46
 */
@Service("personService")
public class PersonService implements InitializingBean, DisposableBean {
	private static Map<String, String> map = new HashMap<String, String>();
	private String message;

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	@PostConstruct
	public void init() {
		System.out.println("I'm  init  method  using  @PostConstrut...." + message);
		map.put("123","456");
	}

	@PreDestroy
	public void destory() {
		System.out.println("I'm  destory method  using  @PreDestroy....." + message);
	}

	public void initByAnnotation() {
		System.out.println("I'm  init  method  using  init-method...." + message);
		map.put("456","789");
	}

	public void destoryByAnnotation() {
		System.out.println("I'm  destory  method  using  destroy-method...." + message);
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		System.out.println("I'm  init  method  using  implements InitializingBean...." + message);
		map.put("789","123");
	}

	@Override
	public void destroy() throws Exception {
		System.out.println("I'm  destory method  using  implements DisposableBean....." + message);

	}

	public void sout(){
		System.out.println(map.toString());
	}
}
